﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class C_mineCubeSiki{

    private E_mineCube mineCube;

    private SpriteRenderer BreakSprite;
    private SpriteRenderer ForeSprite;
    private TextMeshPro textMesh;

    public C_mineCubeSiki(E_mineCube mineCube) {
        this.mineCube = mineCube;
        BreakSprite = mineCube.GetComponent<SpriteRenderer>();
        ForeSprite = mineCube.transform.Find("fore")?.GetComponent<SpriteRenderer>();
        textMesh = mineCube.transform.Find("text")?.GetComponent<TextMeshPro>();
        textMesh.text = "";
        BreakSprite.sprite = M_GameManager.Instance.mineSpriteConfig.GetSpriteWithName("Fore");
        ForeSprite.sprite = null;
    }

    /// <summary>
    /// 更新方块外观
    /// </summary>
    public void UpdateSiki() {

        if (mineCube.mineCubeData.mineState == D_mineState.Open)
        {
            BreakSprite.sprite = M_GameManager.Instance.mineSpriteConfig.GetSpriteWithName("Break");

            if (mineCube.mineCubeData.mineType == D_mineType.Mine)
            {
                //设置前景图为地雷
                ForeSprite.sprite = M_GameManager.Instance.mineSpriteConfig.GetSpriteWithName("Mine");
            }
            else if (mineCube.mineCubeData.mineCount != 0)
            {
                //显示数字
                textMesh.text = mineCube.mineCubeData.mineCount + "";
                //设置前景图为透明
                ForeSprite.sprite = null;
            }
            else
            {
                //设置前景图为透明
                ForeSprite.sprite = null;
            }
        }
        else if (mineCube.mineCubeData.mineState == D_mineState.Mark)
        {
            BreakSprite.sprite = M_GameManager.Instance.mineSpriteConfig.GetSpriteWithName("Fore");
            ForeSprite.sprite = M_GameManager.Instance.mineSpriteConfig.GetSpriteWithName("Mark");
        }
        else if(mineCube.mineCubeData.mineState == D_mineState.Default)
        {
            BreakSprite.sprite = M_GameManager.Instance.mineSpriteConfig.GetSpriteWithName("Fore");
            ForeSprite.sprite = null;
        }
    }
}
